/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrameRelCaixa.java
 *
 * Created on 15/09/2011, 15:18:52
 */
package br.com.GUI.relatorio;

import br.com.classes.Caixa;
import br.com.classes.Movimento;
import br.com.classes.RelLivroCaixa;
import br.com.dao.CaixaDao;
import br.com.dao.RelatorioDao;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Kauane
 */
public class FrameRelCaixa extends javax.swing.JFrame {

    List<Caixa> lista = null;
    
    /** Creates new form FrameRelCaixa */
    public FrameRelCaixa() {
        initComponents();
     
        CarregarCaixa(); // Carrega os caixas        
        
    }

    private FrameRelCaixa(int cod_caixa) {
        
    }
     public void CarregarCaixa() // lista os caixas existentes no banco
    {
        CaixaDao cdao = new CaixaDao();
        lista = cdao.ListarCaixa();

        for (Caixa c : lista) {
            jComboBox_Caixa.addItem(c.getCaixa());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();
        jTextField1 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jYearChooser1 = new com.toedter.calendar.JYearChooser();
        jYearChooser2 = new com.toedter.calendar.JYearChooser();
        jButton1 = new javax.swing.JButton();
        BotaoCancelar = new javax.swing.JButton();
        jComboBox_Caixa = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();

        jTabbedPane1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPane1MouseClicked(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtro por Periodo"));
        jPanel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel2MouseClicked(evt);
            }
        });

        jLabel1.setText("Inicio do Periodo:");

        jLabel2.setText("Fim do Periodo:");

        jLabel6.setText("Saldo inicial:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jDateChooser2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jDateChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Periodo", jPanel2);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtro Anual"));

        jLabel3.setText("Inicio do Periodo:");

        jLabel4.setText("Fim do Periodo:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jYearChooser2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jYearChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jYearChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jYearChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(58, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Anual", jPanel3);

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        BotaoCancelar.setText("Cancelar");
        BotaoCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoCancelarActionPerformed(evt);
            }
        });

        jComboBox_Caixa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jComboBox_CaixaMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jComboBox_CaixaMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jComboBox_CaixaMouseReleased(evt);
            }
        });
        jComboBox_Caixa.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox_CaixaItemStateChanged(evt);
            }
        });
        jComboBox_Caixa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_CaixaActionPerformed(evt);
            }
        });

        jLabel5.setText("Caixa");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Data", "Historico", "Conta", "Credito", "Debito", "Saldo Inicial", "Saldo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setMinWidth(80);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(80);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(80);
        jTable1.getColumnModel().getColumn(1).setMinWidth(200);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(200);
        jTable1.getColumnModel().getColumn(1).setMaxWidth(200);
        jTable1.getColumnModel().getColumn(2).setMinWidth(80);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(80);
        jTable1.getColumnModel().getColumn(2).setMaxWidth(80);
        jTable1.getColumnModel().getColumn(3).setMinWidth(80);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(80);
        jTable1.getColumnModel().getColumn(3).setMaxWidth(80);
        jTable1.getColumnModel().getColumn(4).setMinWidth(80);
        jTable1.getColumnModel().getColumn(4).setPreferredWidth(80);
        jTable1.getColumnModel().getColumn(4).setMaxWidth(80);
        jTable1.getColumnModel().getColumn(5).setMinWidth(80);
        jTable1.getColumnModel().getColumn(5).setPreferredWidth(80);
        jTable1.getColumnModel().getColumn(5).setMaxWidth(80);
        jTable1.getColumnModel().getColumn(6).setMinWidth(80);
        jTable1.getColumnModel().getColumn(6).setPreferredWidth(80);
        jTable1.getColumnModel().getColumn(6).setMaxWidth(80);

        jButton2.setText("Criar PDF");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel7.setText("Saldo Anterior:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox_Caixa, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(BotaoCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 683, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel5))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel7))
                    .addComponent(jComboBox_Caixa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(BotaoCancelar)
                            .addComponent(jButton2))
                        .addGap(0, 158, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BotaoCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoCancelarActionPerformed
        // TODO add your handling code here:
       if(jTabbedPane1.getSelectedIndex()==0){ 
        jDateChooser1.setDate(null);
        jDateChooser2.setDate(null);
        jTextField1.setText("");
      DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
      modelo.setRowCount(0);
       }else if(jTabbedPane1.getSelectedIndex()==1){ 
        jYearChooser1.setYear(2012);
        jYearChooser2.setYear(2012);
        jTextField2.setText("");
      DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
      modelo.setRowCount(0);
       }      
    }//GEN-LAST:event_BotaoCancelarActionPerformed

    private void jComboBox_CaixaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox_CaixaMouseClicked
        // TODO add your handling code here:
}//GEN-LAST:event_jComboBox_CaixaMouseClicked

    private void jComboBox_CaixaMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox_CaixaMousePressed
        // TODO add your handling code here:
}//GEN-LAST:event_jComboBox_CaixaMousePressed

    private void jComboBox_CaixaMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox_CaixaMouseReleased
        // TODO add your handling code here:
}//GEN-LAST:event_jComboBox_CaixaMouseReleased

    private void jComboBox_CaixaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox_CaixaItemStateChanged
        // TODO add your handling code here:
}//GEN-LAST:event_jComboBox_CaixaItemStateChanged

    private void jComboBox_CaixaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_CaixaActionPerformed
      // TODO add your handling code here:
}//GEN-LAST:event_jComboBox_CaixaActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    int selIndex = jTabbedPane1.getSelectedIndex();
    DefaultTableModel modelo = null;
    Double saldo;
  if ((jDateChooser1.getDate() == (null) && (jTabbedPane1.getSelectedIndex()==0))) {  
  
      System.out.println("data null");
    
   }else if(jDateChooser2.getDate() == (null) && (jTabbedPane1.getSelectedIndex()==0) ){
         System.out.println("data null 2");
   }
  
  else if(jTabbedPane1.getSelectedIndex()==0){

        modelo = (DefaultTableModel) jTable1.getModel();
        modelo.setRowCount(0);
        Caixa cx; // Cria um novo objeto caixa
        RelatorioDao rdao = new RelatorioDao();
        FrameRelCaixa rel = new FrameRelCaixa();
        cx = lista.get(jComboBox_Caixa.getSelectedIndex()); // pega o objeto da lista pelo selecionado com combobox 
        Date data = jDateChooser1.getDate();
        Date datapre = jDateChooser2.getDate();
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");   //converte para a data normal
        SimpleDateFormat formatoBanco = new SimpleDateFormat("yyyy-MM-dd");  // converte para a data do banco
        
        String dataformatadapre = formato.format(datapre);
        String dataini = formatoBanco.format(data);
        String datafim = formatoBanco.format(datapre);

        RelatorioDao rla = new RelatorioDao();  
        List<RelLivroCaixa> listarel = rla.RelatorioPDF(cx.getCod_caixa(), dataini, datafim);
     
        for(RelLivroCaixa rl : listarel) {
            DecimalFormat FormataTable = new DecimalFormat("#,##0.00");
            for (int i = 0; i < listarel.size(); i++) {  
        if(i==0){
          saldo = listarel.get(i).getSaldoini();  
          jTextField2.setText(FormataTable.format(listarel.get(i).getSaldoini()));
                }
        }           
           String dataformatada = formato.format(rl.getData_mov()); 
           modelo.addRow(new Object[]{dataformatada, rl.getMov_historico(),rl.getConta(), FormataTable.format(rl.getCredito()), FormataTable.format(rl.getDebito()), FormataTable.format(rl.getSaldoini()), FormataTable.format(rl.getSaldo())});
        }      
  }
  else if (jTabbedPane1.getSelectedIndex()==1){

      modelo = (DefaultTableModel) jTable1.getModel();
      modelo.setRowCount(0);
      
      int anoini = jYearChooser1.getYear();
      String dataini = "-01-01";
      int anofim = jYearChooser2.getYear();
      String datafim = "-12-31"; 
      
        Caixa cx; // Cria um novo objeto caixa
        RelatorioDao rdao = new RelatorioDao();
        FrameRelCaixa rel = new FrameRelCaixa();
        cx = lista.get(jComboBox_Caixa.getSelectedIndex()); // pega o objeto da lista pelo selecionado com combobox 
        
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");   //converte para a data normal
        SimpleDateFormat formatoBanco = new SimpleDateFormat("yyyy-MM-dd");  // converte para a data do banco

        RelatorioDao rla = new RelatorioDao();  
        List<RelLivroCaixa> listarel = rla.RelatorioPDF(cx.getCod_caixa(), anoini+dataini, anofim+datafim);

        for(RelLivroCaixa rl : listarel) {
        DecimalFormat FormataTable = new DecimalFormat("#,##0.00");
            for (int i = 0; i < listarel.size(); i++) {  
          if(i==0){
          saldo = listarel.get(i).getSaldoini();  
          jTextField2.setText(FormataTable.format(listarel.get(i).getSaldoini()));
   }
} 
          String dataformatada = formato.format(rl.getData_mov()); 
          modelo.addRow(new Object[]{dataformatada, rl.getMov_historico(),rl.getConta(), FormataTable.format(rl.getCredito()), FormataTable.format(rl.getDebito()), FormataTable.format(rl.getSaldoini()), FormataTable.format(rl.getSaldo())});
        }  
  }         
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
           int selIndex = jTabbedPane1.getSelectedIndex();
    DefaultTableModel modelo = null;
    Double saldo;
  if ((jYearChooser1.getYear() == (0) && (jTabbedPane1.getSelectedIndex()==1))) {  
  
      System.out.println("data null");
    
   }else if(jYearChooser2.getYear() == (0) && (jTabbedPane1.getSelectedIndex()==1) ){
         System.out.println("data null 2");
   }
  
  else if(jTabbedPane1.getSelectedIndex()==0){
             
        Caixa cx; // Cria um novo objeto caixa
        RelatorioDao rdao = new RelatorioDao();
        FrameRelCaixa rel = new FrameRelCaixa();
        cx = lista.get(jComboBox_Caixa.getSelectedIndex()); // pega o objeto da lista pelo selecionado com combobox 
        Date data = jDateChooser1.getDate();
        Date datapre = jDateChooser2.getDate();
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");   //converte para a data normal
        SimpleDateFormat formatoBanco = new SimpleDateFormat("yyyy-MM-dd");  // converte para a data do banco
        String dataformatada = formatoBanco.format(data);
        String dataformatadapre = formatoBanco.format(datapre);
        String dataini = formatoBanco.format(data);
        String datafim = formatoBanco.format(datapre); 

        PrimeiroPDF p = new PrimeiroPDF();
        try {
            p.main(cx.getCod_caixa(), dataini, datafim, cx.getCxNomeEmp());
        } catch (Exception ex) {
            Logger.getLogger(FrameRelCaixa.class.getName()).log(Level.SEVERE, null, ex);
        }
  }
        else if (jTabbedPane1.getSelectedIndex()==1){
      
         int anoini = jYearChooser1.getYear();
      String dataini = "-01-01";
         int anofim = jYearChooser2.getYear();
      String datafim = "-12-31"; 

        Caixa cx; // Cria um novo objeto caixa
        RelatorioDao rdao = new RelatorioDao();
        FrameRelCaixa rel = new FrameRelCaixa();
        cx = lista.get(jComboBox_Caixa.getSelectedIndex()); // pega o objeto da lista pelo selecionado com combobox 
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");   //converte para a data normal
        SimpleDateFormat formatoBanco = new SimpleDateFormat("yyyy-MM-dd");  // converte para a data do banco
     
        PrimeiroPDF p = new PrimeiroPDF();
        try {
            p.main(cx.getCod_caixa(), anoini+dataini, anofim+datafim, cx.getCaixa());
        } catch (Exception ex) {
            Logger.getLogger(FrameRelCaixa.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane1MouseClicked
        // TODO add your handling code here:
        int clik=1;
    }//GEN-LAST:event_jTabbedPane1MouseClicked

    private void jPanel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel2MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel2MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrameRelCaixa().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotaoCancelar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox_Caixa;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private com.toedter.calendar.JDateChooser jDateChooser2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private com.toedter.calendar.JYearChooser jYearChooser1;
    private com.toedter.calendar.JYearChooser jYearChooser2;
    // End of variables declaration//GEN-END:variables
}
